function JoinGroup(sGrid, sTargetId)
{
var memberXml = "";
var oTypeToAdd = "4007";
var lookupType = "ResourceGroupItems";
var lookupSelectionStatus = "multi";
var oTypesToAdd = ResourceGroup.toString();

var retval = LookupObjects(null, lookupSelectionStatus, lookupType, oTypesToAdd, 0);
var retvals = "";

if (!retval || retval.items.length == 0)
{

return false;
}
else
{
for (i=0; i<retval.items.length; i++)
{
retvals += retval.items[i].id + ";";
}



retvals = retvals.substr(0, retvals.length-1);

memberXml = "<membership>";

memberXml += "<resources>" + sTargetId + "</resources>";

memberXml += "<resourcegroups>" + retvals + "</resourcegroups></membership>";

var oXml = CreateXmlDocument(false);
oXml.loadXML(memberXml);


var xmlhttp = CreateXmlHttp();
xmlhttp.open("POST", prependOrgName("/_grid/cmds/cmd_additems.aspx"), false);
SetTokenInHeader(xmlhttp, prependOrgName("/_grid/cmds/cmd_additems.aspx"));
xmlhttp.send(oXml);





var oXml = CreateXmlDocument(false);
oXml.loadXML(xmlhttp.responseXML.xml);

if (sGrid && handleXMLErr(oXml))
{
document.all[sGrid].Refresh();
}
}
}

function DepartGroup(sGrid, sTargetId)
{
var a = getSelected(sGrid);
if (a.length > 0)
{
if (openStdDlg(prependOrgName("/_grid/cmds/dlg_departgroups.aspx?iTotal=") + a.length + "&targetid=" + sTargetId, a, 400, 230))
{
document.all[sGrid].Refresh();
}
return;
}
else
{
alert( LOCID_ACTION_NOITEMSELECTED );
}
}






function PublishResourceGroups( )
{
var command = new RemoteCommand("ResourceSpecTree", "PublishResourceGroups");
command.Execute(PublishResourceGroupsCallback);
}








function PublishResourceGroupsCallback( oResult )
{
if (!oResult.Success)
{
return;
}
}


function deleteGroup(sGrid)
{
var a = getSelected(sGrid);
if (a.length > 0)
{
if (!CheckForReferences(a))
{
return;
}
}


doAction(sGrid, ResourceGroup, "delete");
}



function CheckForReferences(aTargetGuids)
{

aTargetGuids.type = "guid";

var oCommand = new RemoteCommand("ResourceGroupUI", "IsResourceGroupChild");
if (oCommand != null)
{
oCommand.SetParameter("ids", aTargetGuids);

var oResult = oCommand.Execute();
if (oResult.Success)
{
if ( oResult.ReturnValue )
{

return openStdDlg(prependOrgName("/SM/ResourceGroups/deletewarndialog.aspx"), null, 460, 270);
}
}

}
return true;
}
